import 'package:flutter_trip/model/config_model.dart';

import 'common_model.dart';
import 'grid_nav_model.dart';
import 'sales_box_model.dart';

class HomeModel {
  final ConfigModel? config;
  final List<CommonModel>? bannerList;
  final List<CommonModel>? localNavList;
  final List<CommonModel>? subNavList;
  final GridNavModel? gridNav;
  final SalesBoxModel? salesBox;
  HomeModel({this.config, this.bannerList,
    this.localNavList,this.subNavList,
    this.gridNav, this.salesBox});

  factory HomeModel.fromJson(Map<String, dynamic> json) {

    var localNavListJson = json['localNavList'] as List;
    List<CommonModel> localNavList = localNavListJson.map((i) => CommonModel.fromJson(i)).toList();

    var bannerListJson = json['bannerList'] as List;
    List<CommonModel> bannerList = bannerListJson.map((i) => CommonModel.fromJson(i)).toList();


    var subNavListJson = json['subNavList'] as List;
    List<CommonModel> subNavList = subNavListJson.map((i) => CommonModel.fromJson(i)).toList();

    return HomeModel(
      localNavList: localNavList,
      bannerList: bannerList,
      subNavList: subNavList,
      config: ConfigModel.fromJson(json['config']),
      gridNav: GridNavModel.fromJson(json['gridNav']),
      salesBox: SalesBoxModel.fromJson(json['salesBox']),
    );
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = <String, dynamic>{};
    if (config != null) {
      data['config'] = config!.toJson();
    }
    if (bannerList != null) {
      data['bannerList'] = bannerList!.map((v) => v.toJson()).toList();
    }
    if (localNavList != null) {
      data['localNavList'] = localNavList!.map((v) => v.toJson()).toList();
    }
    if (gridNav != null) {
      data['gridNav'] = gridNav!.toJson();
    }
    if (subNavList != null) {
      data['subNavList'] = subNavList!.map((v) => v.toJson()).toList();
    }
    if (salesBox != null) {
      data['salesBox'] = salesBox!.toJson();
    }
    return data;
  }
}